#pragma once

#include <memory>
#include <thread>
#include <cmath>
#include <chrono>
#include <cassert>
#include <queue>
#include <concurrentqueue.h>
#include <mutex>
#include <condition_variable>
#include "utils/utils.h"
#include "model/ClientNode.h"
#include "protocol/routeinfo.pb.h"
#include "protocol/transport.pb.h"
 
#include "base/Uri.h"
#include "base/Traits.h"
#include "base/Timer.h"
#include "base/Serializer.h"
#include "base/Define.h"
#include "base/MessageLoop.h"

namespace zeroplus::mq::producer
{
    class ProducerMediator;
    class RouteInfoDownloader
    {
    private:
        std::shared_ptr<ClientNode> client_;
        MessageLoop loop_;
        std::shared_ptr<Timer> timer_;
        moodycamel::ConcurrentQueue<std::string> pendingTopicQueue_;
        std::shared_ptr<ProducerMediator> mediator_;

    public:
        RouteInfoDownloader(std::shared_ptr<ProducerMediator> mediator, std::string uri);

        ~RouteInfoDownloader();

        void Start();

        void SendQueryRouteInfoRequest();

        void InternalReceive(const std::string &topic);
    };
}
